#include <iostream>
#include <cstring>
#include <vector>
#include <map>
#include <string>
#include <set>
#include <algorithm>
#include <cmath>
#define int long long
using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<int>arr[n + 10];
    for(int i = 1; i <= n; i ++) 
    {
        int x;
        cin >> x;
        arr[x].push_back(i);
    }
    vector<int>ans;
    for(int i = 1; i <= n; i ++)
    {
        for(int j = 1; j < arr[i].size(); j ++)
        {
            if(arr[i][j] - arr[i][j - 1] <= 2)
            {
                ans.push_back(i);
                break;
            }
        }
    }
    for(int i = 0; i < ans.size(); i ++) cout << ans[i] << " ";
}

signed main()
{
    int t = 1;
    cin >> t;
    while(t --)
    {
        solve();
    }
}
